/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fix.it.source.fixit;

import java.math.BigInteger;
import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import sun.security.util.BigInt;

/**
 *
 * @author Biserka
 */
@ManagedBean(name="mConverterBean")
@FacesConverter(value = "municipalityConverter")
public class MunicipalityConverter implements Converter {
@PersistenceContext
    private transient EntityManager em;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return em.find(Municipality.class, new Long(value));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
          return ((Municipality) value).getId().toString();

    }
}
